const os = require('os');


/**
 * 网络工具类
 * @author Zhang
 * @date 2019-2-1 11:13:44
 * @abstract
 */
export class NetworkUtils {

  /**
   * 获取本机所有IP
   * @return {string[]}
   */
  static getLocalIpAddrs() {
    const ips = [];
    const network = os.networkInterfaces();
    for (const item of Object.values(network)) {
      // @ts-ignore
      for (const networkItem of item) {
        if (networkItem.family === 'IPv4') {
          ips.push(networkItem.address);
        }
      }
    }
    return ips;
  }

}
